import 'package:flutter/material.dart';
import 'package:flutter_application_1/Global.dart';

class SearchRow extends StatefulWidget {
  final Color? primaryColor;
  final Function(String) onChanged;
  final FocusNode? focusNode;

  SearchRow({
    this.primaryColor,
    required this.onChanged,
    this.focusNode,
  });

  @override
  State<StatefulWidget> createState() => SearchRowState();
}

class SearchRowState extends State<SearchRow> {
  @override
  Widget build(BuildContext context) {
    return SliverAppBar(
      backgroundColor: widget.primaryColor ?? Global.Primary_Color,
      automaticallyImplyLeading: false,
      pinned: true,
      title: Container(
        height: kToolbarHeight * 2 / 3,
        padding: EdgeInsets.symmetric(horizontal: 8),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius:
              BorderRadius.all(Radius.circular(kToolbarHeight * 2 / 3)),
        ),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Icon(
              Icons.search,
              color: Colors.black,
              size: 20,
            ),
            Expanded(
              flex: 1,
              child: TextField(
                focusNode: widget.focusNode,
                cursorColor: Colors.black,
                cursorWidth: 1,
                style: TextStyle(
                  fontSize: 15,
                  textBaseline: TextBaseline.alphabetic,
                ),
                decoration: InputDecoration(
                  hintText: '输入城市名进行搜索',
                  border: InputBorder.none,
                  contentPadding: EdgeInsets.symmetric(
                    vertical: 8,
                    horizontal: 6,
                  ),
                  isDense: true,
                ),
                textInputAction: TextInputAction.search,
                onChanged: (String value) {
                  widget.onChanged(value);
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
